<?php

namespace App\Modules\Index\Models;


use Illuminate\Database\Eloquent\Model;

/**
 * @package App\Modules\Index\Models
 *
 */
class Glucose extends Model
{
    protected $table = 'glucose';

    protected $fillable = ['id','user_id', 'glu', 'device_code', 'type', 'meals','state','type', 'diet', 'sport', 'remark', 'test_at', 'created_at', 'updated_at'];


    /**
     * 添加血糖
     * @param $param
     * @return mixed
     */
    static function addGlu($param)
    {
        // TODO check
        return self::create($param);
    }

    /**
     * 获取用户当天的测量数据(只查询设备自动录入的)
     */
    public static function dayGlucose($user_id,$start_time,$end_time){
        return self::where('user_id',$user_id)->where('type',2)->where('test_at','>=',$start_time)->where('test_at','<=',$end_time)->get();
    }
}